package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectPageDTO;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.CustomerOrdersMapper;
import com.zzyl.service.CustomerOrdersService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerOrdersServiceImpl implements CustomerOrdersService {

    @Autowired
    private CustomerOrdersMapper customerOrdersMapper;
    /**
     * 条件分页查询护理项
     *
     * @param nursingProjectPageDTO
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> pageCondition(NursingProjectPageDTO nursingProjectPageDTO) {

        PageHelper.startPage(nursingProjectPageDTO.getPageNum(),nursingProjectPageDTO.getPageSize());
        Page<NursingProjectVo> page =  customerOrdersMapper.pageCondition(nursingProjectPageDTO);
        PageResponse<NursingProjectVo> response = PageResponse.of(page, NursingProjectVo.class);
        return  response;

    }

    /**
     * 根据Id查询护理项目
     *
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        NursingProjectVo nursingProjectVo = customerOrdersMapper.getById(id);
        nursingProjectVo.setCount(customerOrdersMapper.projectRefCount(id));
        return nursingProjectVo;
    }
}
